home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / Extras / SubMenus / MenuDemoWindow.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  3.9 KB  |  120 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ////////////////////////////////////////////////////////////////////
  22. // MenuDemoWindow.C: Demonstrate Cmd and MenuBar classes
  23. ////////////////////////////////////////////////////////////////////
  24.  
  25. //////////////////////////////////////////////////////////////////////
  26. // NOTE: This program is similar to the program described in the book, 
  27. // but demonstrates the enhanced CmdList/MenuBar classes that support
  28. // cascading submenus.
  29. //////////////////////////////////////////////////////////////////////
  30.  
  31. #include "MenuDemoWindow.h"
  32. #include "MenuBar.h"
  33. #include "MenuDemoApp.h"
  34. #include "NoOpCmd.h"
  35. #include "UndoCmd.h"
  36. #include "CmdList.h"
  37. #include <Xm/DrawingA.h>
  38.  
  39. MenuDemoWindow::MenuDemoWindow ( char *name ) : MenuWindow ( name )
  40. {
  41.     // Create three NoOpCmd objects to demonstrate relationships
  42.     // between objects, as well as MotifApp's undo facility
  43.     
  44.     _a = new NoOpCmd ( "A", TRUE );
  45.     _b = new NoOpCmd ( "B", TRUE );
  46.     _c = new NoOpCmd ( "C", FALSE );
  47.     
  48.     // Set up dependencies between objects. Each command disables
  49.     // itself once it is executed, and enables the other two
  50.     
  51.     _a->addToActivationList ( _b );
  52.     _a->addToActivationList ( _c );
  53.     _a->addToDeactivationList ( _a );
  54.     
  55.     _b->addToActivationList ( _a );
  56.     _b->addToActivationList ( _c );
  57.     _b->addToDeactivationList ( _b );
  58.     
  59.     _c->addToActivationList ( _a );
  60.     _c->addToActivationList ( _b );
  61.     _c->addToDeactivationList ( _c );
  62. }
  63.  
  64. Widget MenuDemoWindow::createWorkArea ( Widget parent )
  65. {
  66.     _canvas = XtCreateWidget ( "canvas", 
  67.                   xmDrawingAreaWidgetClass,
  68.                   parent, 
  69.                   NULL, 0 );
  70.     return _canvas;    
  71. }
  72.  
  73. void MenuDemoWindow::createMenuPanes()
  74. {
  75.     CmdList *appCmdList, *xyzCmdList, *abcCmdList, *subCmdList;
  76.     
  77.     // Create an Application pane containing undo, 
  78.     // and other application-wide commands
  79.     
  80.     appCmdList = new CmdList("Application");
  81.     appCmdList->add ( theUndoCmd );        
  82.     appCmdList->add ( theMenuDemoApp->manageCmd() );
  83.     appCmdList->add ( theMenuDemoApp->iconifyCmd() );
  84.     appCmdList->add ( theMenuDemoApp->quitCmd() );
  85.     _menuBar->addCommands ( appCmdList );
  86.  
  87.     // Create a submenu cmd list
  88.  
  89.     subCmdList = new CmdList("SubMenu");
  90.     subCmdList->add ( _a );
  91.     subCmdList->add ( _b );
  92.     subCmdList->add ( _c );
  93.  
  94.     // Create a menu pane of NoOpCmd objects to demonstrate
  95.     // Cmd objects that have multiple interfaces.
  96.     // Note that the _a, _b, and _c commands are
  97.     // present in both this pane (as a submenu)
  98.     // and the following direct menu pane
  99.     
  100.     xyzCmdList = new CmdList("XYZ");
  101.     xyzCmdList->add ( theMenuDemoApp->xCmd() );
  102.     xyzCmdList->add ( theMenuDemoApp->yCmd() );
  103.     xyzCmdList->add ( theMenuDemoApp->zCmd() );
  104.     xyzCmdList->add ( subCmdList );
  105.     _menuBar->addCommands ( xyzCmdList );
  106.     
  107.     // Create a window-specific menu pane, containing 
  108.     // commands that are independent within each window.
  109.     
  110.     abcCmdList = new CmdList("ABC");
  111.     abcCmdList->add ( _a );
  112.     abcCmdList->add ( _b );
  113.     abcCmdList->add ( _c );
  114.     _menuBar->addCommands ( abcCmdList );
  115.  
  116. }
  117.  
  118.  
  119.  
  120.